<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	template="/WEB-INF/templates/default.xhtml">
	<ui:define name="content">
		<h2>Meu Carrinho</h2>
		<div id="entrega">
		<h:form id="form-carrinho">
			<h:dataTable var="item" value="#{carrinho.pedido.itens}" id="carrinho-itens">
				<h:column>
					<f:facet name="header">Produto</f:facet>
                #{item.produto.nome}
				</h:column>
				<h:column>
					<f:facet name="header">Quantidade</f:facet>
                <h:inputText value="#{item.quantidade}" valueChangeListener="carrinho.alterarQuantidade" size="2" />
            </h:column>
				<h:column>
					<f:facet name="header">Valor unitário</f:facet>
                R$ #{item.produto.valorVenda}
            </h:column>
				<h:column>
					<f:facet name="header">Sub-total</f:facet>
					R$ #{item.subtotal}
				</h:column>
				<f:facet name="footer">
					<tr>
						<th class="carrinho-total-itens" colspan="3">Total em compras</th>
						<th class="carrinho-total-itens">R$ <h:outputText value="#{carrinho.pedido.valorTotalItens}" /></th>
					</tr>
					<tr>
						<th class="carrinho-frete" colspan="3">Frete</th>
						<th class="carrinho-frete">R$ <h:outputText value="#{carrinho.pedido.valorFrete}" /></th>
					</tr>
					<tr>
						<th class="carrinho-total" colspan="3">Total do Pedido</th>
						<th class="carrinho-total">R$ <h:outputText value="#{carrinho.pedido.valorTotalPedido}" /></th>
					</tr>
				</f:facet>
			</h:dataTable>
			<div id="entrega">
			<fieldset id="cliente">
				<legend>Cliente</legend>
				<h:panelGroup rendered="#{carrinho.clientePF != null}">
					<div class="linha"><label>Nome: </label><h:outputText value="#{carrinho.clientePF.nome}" /></div>
					<div class="linha"><label>CPF: </label><h:outputText value="#{carrinho.clientePF.cpf}" /></div>
					<div class="linha"><label>Sexo: </label><h:outputText value="#{carrinho.clientePF.sexo}" /></div>
					<div class="linha"><label>Data de Nascimento: </label><h:outputText value="#{carrinho.clientePF.dataNascimento}" /></div>
					<div class="linha"><label>E-mail: </label><h:outputText value="#{carrinho.clientePF.email}" /></div>
				</h:panelGroup>
				<h:panelGroup rendered="#{carrinho.clientePJ != null}">
					<div class="linha"><label>Razão Social: </label><h:outputText value="#{carrinho.clientePJ.razaoSocial}" /></div>
					<div class="linha"><label>CNPJ: </label><h:outputText value="#{carrinho.clientePF.cnpj}" /></div>
					<div class="linha"><label>E-mail: </label><h:outputText value="#{carrinho.clientePF.email}" /></div>
				</h:panelGroup>
			</fieldset>
			<fieldset id="endereco">
				<legend>Endereço de Entrega</legend>
				<div class="linha"><label>Logradouro:</label><h:inputText value="#{carrinho.pedido.cliente.endereco.logradouro}" /></div>
				<div class="linha"><label>Número:</label><h:inputText value="#{carrinho.pedido.cliente.endereco.numero}" /></div>
				<div class="linha"><label>Complemento:</label><h:inputText value="#{carrinho.pedido.cliente.endereco.complemento}" /></div>
				<div class="linha"><label>Bairro:</label><h:inputText value="#{carrinho.pedido.cliente.endereco.bairro}" /></div>
				<div class="linha"><label>Cidade:</label><h:inputText value="#{carrinho.pedido.cliente.endereco.cidade}" /></div>
				<div class="linha"><label>UF:</label><h:inputText value="#{carrinho.pedido.cliente.endereco.uf}" /></div>
				<div class="linha"><label>CEP:</label><h:inputText value="#{carrinho.pedido.cliente.endereco.cep}" /></div>
				<div class="linha"><h:commandButton action="#{carrinho.calcularFrete}" value="Calcular Frete" /></div>
			</fieldset>
			<div style="clear:both"><br /></div>
			</div>
		</h:form>
		</div>

		<!--  
      <h:form id="reg">
         <h2>Register (Bean Validation example)</h2>
         <p>Enforces annotation-based constraints defined on the
            model class.</p>
         <table>
            <tr>
               <th style="text-align: right;"><h:outputLabel
                     for="name" value="Name:" /></th>
               <td><h:inputText id="name" value="#{newMember.name}" />
                  <h:message for="name" errorClass="invalid" /></td>
            </tr>
            <tr>
               <th style="text-align: right;"><h:outputLabel
                     for="email" value="Email:" /></th>
               <td><h:inputText id="email"
                     value="#{newMember.email}" /> <h:message
                     for="email" errorClass="invalid" /></td>
            </tr>
            <tr>
               <th style="text-align: right;"><h:outputLabel
                     for="phoneNumber" value="Phone #:" /></th>
               <td><h:inputText id="phoneNumber"
                     value="#{newMember.phoneNumber}" /> <h:message
                     for="phoneNumber" errorClass="invalid" /></td>
            </tr>
         </table>
         <p>
            <h:commandButton id="register"
               action="#{memberRegistration.register}" value="Register" />
            <h:outputText value=" Registered!"
               rendered="#{facesContext.postback and empty facesContext.messageList}"
               style="color: green;" />
         </p>
      </h:form>
      <h2>Members</h2>
      <h:panelGroup rendered="#{empty members}">
         <em>No registered members.</em>
      </h:panelGroup>
      <h:dataTable var="_member" value="#{members}"
         rendered="#{not empty members}">
         <h:column>
            <f:facet name="header">Id</f:facet>
                #{_member.id}
            </h:column>
         <h:column>
            <f:facet name="header">Name</f:facet>
                #{_member.name}
            </h:column>
         <h:column>
            <f:facet name="header">Email</f:facet>
                #{_member.email}
            </h:column>
         <h:column>
            <f:facet name="header">Phone #</f:facet>
                #{_member.phoneNumber}
            </h:column>
         <h:column>
            <f:facet name="header">REST URL</f:facet>
            <a href="#{request.contextPath}/rest/members/#{_member.id}">/rest/members/#{_member.id}</a>
         </h:column>
         <f:facet name="footer">
                REST URL for all members: <a
               href="#{request.contextPath}/rest/members">/rest/members</a>
         </f:facet>
      </h:dataTable>
      -->
	</ui:define>
</ui:composition>
